
// 引入token
const jsonwebtoken = require('jsonwebtoken')
// 设置密钥
const secret = "Elijah"
const JWT = {
    generate(value, expires) {
        // 注册
        return jsonwebtoken.sign(value, secret, { expiresIn: expires })
    },
    // 验证token
    verify(token) {
        try {
            return jsonwebtoken.verify(token, secret)
        } catch (error) {
            return false
        }
    }

}
// 测试
/* const token = JWT.generate({ name: "Elijah" }, "10s")
console.log(JWT.verify(token));
setTimeout(() => {
    console.log(JWT.verify(token));

},11000) */
module.exports = JWT
